package com.yunxin.core.infra.persistence.repository.user;

import com.yunxin.core.application.dto.order.OrderUserApplyPageDTO;
import com.yunxin.core.domain.model.user.UserIpInfo;
import com.yunxin.core.domain.model.user.UserIpInfoRepository;
import com.yunxin.core.infra.persistence.converter.UserInfoConverter;
import com.yunxin.core.infra.persistence.entity.user.UserIpInfoDO;
import com.yunxin.core.infra.persistence.mapper.user.UserIpInfoExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zero°
 * @since 2023-11-25
 */
@Repository
@RequiredArgsConstructor
public class UserInfoInfoRepositoryImpl implements UserIpInfoRepository {

    private final UserIpInfoExtendMapper userIpInfoExtendMapper;

    private final UserInfoConverter userInfoConverter;

    @Override
    public boolean saveUserIpInfo(UserIpInfo userIpInfo) {
        UserIpInfoDO userIpInfoDO = userInfoConverter.formUserIpInfo(userIpInfo);
        int count = userIpInfoExtendMapper.insertSelective(userIpInfoDO);
        return count > 0;
    }

    @Override
    public Long getUserIpInfoIdByVisitorAndChannelPromotion(String ip, String channelPromotionCode) {
        return userIpInfoExtendMapper.getUserIpInfoIdByVisitorAndChannelPromotion(ip, channelPromotionCode);
    }

    @Override
    public List<UserIpInfo> selectIpList(String start,String end) {
        return userIpInfoExtendMapper.selectIpList(start,end);
    }
}
